package com.snatch.data.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.snatch.common.constant.SnatchConstant;
import com.snatch.data.service.CheckService;
import com.snatch.data.service.OddsService;

@Controller
@RequestMapping("/data")
public class OddsController {
	
	@Autowired
	private OddsService oddsService;
	@Autowired
	private CheckService checkService;
	
	public String findleague(Model model,String webCode,String gameCode,String leagueid,String matchid){
		
		/*List<SnatchGame> snatchGames = snatchService.findGames(webCode);
		List<League> leagues = adminDataService.findLeagues(webCode,gameCode);
		List<Match> matchs = new ArrayList<Match>();
		ThirdMatchDto thirdMatch = null;
		if(null != leagueid){
			matchs = adminDataService.findMatchs(webCode, gameCode, leagueid);
			if(null != matchid){
				thirdMatch = adminDataService.findThirdMatch(webCode, gameCode, leagueid, matchid);
			}
		}
		
		model.addAttribute("snatchGames",snatchGames);
		model.addAttribute("leagues",leagues);
		model.addAttribute("matchs",matchs);
		model.addAttribute("thirdMatch",thirdMatch);
		
		model.addAttribute("webCode", webCode);
		model.addAttribute("gameCode", gameCode);
		model.addAttribute("leagueid", leagueid);
		model.addAttribute("matchid", matchid);*/
		return "data/thirdMatch";
	}
	
	
	@RequestMapping(value="odds", produces = "application/xml;charset=UTF-8")  
	public @ResponseBody String getSportsOdds(String ident,String uuid,String webCode,String gameCode,String gameType,String lastTime) {
		int code = checkService.checkUser(ident, uuid);
		if(SnatchConstant.SUCCESS != code){
			return checkService.checkFailXml(code);
		}
		if(null == webCode){
			webCode = SnatchConstant.THIRD_SYSTEM_HG_VALUE;
		}
		if(null == gameCode){
			gameCode = SnatchConstant.FOOTBALL;
		}
		if(null == gameType){
			gameType = SnatchConstant.SNATCH_TYPE_GQ;
		}
		if(null == lastTime){
			lastTime = "";
		}
		return  oddsService.oddsData(webCode, gameCode,gameType, lastTime);
 
	}
	
	@RequestMapping(value="live", produces = "application/xml;charset=UTF-8")  
	public @ResponseBody String getLive(String webCode,String gameCode,String lastTime) {
		if(null == webCode){
			webCode = SnatchConstant.THIRD_SYSTEM_HG_VALUE;
		}
		if(null == gameCode){
			gameCode = SnatchConstant.FOOTBALL;
		}
		if(null == lastTime){
			lastTime = "";
		}
		String xml = oddsService.liveData(webCode, gameCode, lastTime);
		System.out.println(xml);
		return  xml;
 
	}
}
